package com.tsd.core.shiro.config;

import com.tsd.core.shiro.IShiroConst;
import org.apache.shiro.authc.UsernamePasswordToken;

/**
 * @ClassName: ShiroAuthToken
 * @Description: 自定义Token
 * @Author: Hillpool
 * @Date: 2022/7/15 9:54
 * @Version: 1.0
 */
public class ShiroAuthToken extends UsernamePasswordToken {

    private String token;

    private String refresh_token = null;

    private String account_set_sid = null;

    private String login_type;

    private String device_type;

    public ShiroAuthToken(final String username, final String password, final String token,
                          final String login_type, final String device_type) {
        super(username, password);
        this.token = token;
        this.login_type = login_type;
        this.device_type = device_type;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String getRefresh_token() {
        return refresh_token;
    }

    public void setRefresh_token(String refresh_token) {
        this.refresh_token = refresh_token;
    }

    public String getAccount_set_sid() {
        return account_set_sid;
    }

    public void setAccount_set_sid(String account_set_sid) {
        this.account_set_sid = account_set_sid;
    }

    public String getLogin_type() {
        return login_type;
    }

    public void setLogin_type(String login_type) {
        this.login_type = login_type;
    }

    public String getDevice_type() {
        return device_type;
    }

    public void setDevice_type(String device_type) {
        this.device_type = device_type;
    }

    /**
     * 祖父类  --- AuthenticationToken
     * Object getPrincipal();    --- 资源对象
     * Object getCredentials();  --- 比较对象
     * 1.如果是普通登陆 返回密码
     * 2.如果是Token访问 返回token
     * 目前只有两种Realm
     * ... ...
     *
     * @return
     */
    @Override
    public Object getCredentials() {
        if (IShiroConst.REALM_NAME_TOKEN.equals(this.getLogin_type())) {
            return this.getToken();
        }
        return this.getPassword();
    }
}
